*** set up directories; for example, the authors had the following
if c(username)=="oficina" 	cd "/Users/oficina/Dropbox (Personal)/skills_survey/Survey_adaptive/ReStat Replication and Publication Materials/data"
else {
	loc user "`c(username)'"
	cd "C:\Users\Ken\Dropbox\skills_survey\Survey_adaptive\ReStat Replication and Publication Materials\data"
}
set varabbrev on
set graphics off

*** this dataset is used for the main tables and figures in the text
*** it is based on the first sample generated from our quota-procedure, and does not include supplemental data to obtain less educated adults
*** the weights are constructed using ipfraking and are based on quota-variables: race/ethnicity, party, age, and income	
u "preferred_sampleRR_uniwts", clear

*u "undereducsampRR", clear
** data stuff
cap drop _one
gen _one = 1

gen noveil = veil==0
sum personalinc,d
gen highinc = 1 if personalinc>=`r(p50)'
gen lowinc = 1 if personalinc<=`r(p50)'

* set these here, allows us to change inc from median to mean 
global incmedmrs  59.339 	// median 
global incmrs  71.419	// this is the median of the mean (the other statistics use the median as well)
global mobmrs  68.26
global iirmrs  11.5
global primrs 15
global elimrs 163.384

global pripct 1468.567	// based on linear regression of percentile against bottom 20 income
global elipct 9770.1	// based on linear regression of percentile against top 20 income
global mobpct 2.054		// based on linear regression of percentile against mobility 
global iirpct 1.12088		// based on linear regression of percentile against IIR

gen young = age_1824 ==1 | age_2534==1 | age_3544==1
gen old   = age_4554 ==1 | age_55pl==1
foreach v in p10socB_q p50socB_q p90socB_q avgincsocB_q p10socA_q p50socA_q p90socA_q avgincsocA_q {
	replace `v' = `v'*1000
	}
gen p10incdiff = ln(inc/p10socB_q)
gen p50incdiff = ln(inc/p50socB_q)
gen p90incdiff = ln(inc/p90socB_q)
gen avgincdiff = ln(inc/avgincsocB_q)

label var avginc_q "Middle Income" 
label var p50inc_q "Middle Income" 
label var mob_q "Income Mobility"
label var iir_q "Income Inequality Ratio"
label var p10inc_q "Income 10th Percentile"
label var p90inc_q "Income 90th Percentile"

graph set window fontface "Times New Roman"


***********************************************
/* TABLE 1: RANDOMIZATION VALUES */
***********************************************

** values for Table 1 are based on analysis of CPS and mobility data from the opportunity project 
** code that generates these values is replication_randomization_values.do

***********************************************
/* TABLE 2: DESCRIPTIVE STATISTICS OF SAMPLE */
***********************************************

preserve
	gen livedup=(past>0 & past!=.)
	label variable livedup "Exceeded parent's income"
	gen beliefupmob=(belief_mob>0 & belief_mob!=.)
	label variable beliefupmob "Believes U.S. ``land of opportunity''"
	gen HS=educ_hs
	gen Inter=educ_2yr+educ_somecoll
	gen Bachelor=educ_4yr+educ_4yrplus
	gen Democrat=(polgroup==1)
	gen Independent=(polgroup==2)
	gen Republican=(polgroup==3)
	gen age=age_alt
	replace age=21 if age_alt==. & age_1824==1
	replace age=30 if age_alt==. & age_2534==1
	replace age=40 if age_alt==. & age_3544==1
	replace age=50 if age_alt==. & age_4554==1
	replace age=64 if age_alt==. & age_55pl==1
	label variable age "Age"
	
	keep if question==1
	estpost su HS Inter Bachelor Democrat Republican Independent age gender_female race_white race_black race_hispanic inc /*Trump Clinton*/ livedup /*expectedupmob*/ beliefupmob , esample
	est store A
	estpost su HS Inter Bachelor Democrat Republican Independent age gender_female race_white race_black race_hispanic inc /*Trump Clinton*/ livedup /*expectedupmob*/ beliefupmob [aw=rakedwgt], esample
	est store B
	
	** WILL NEED TO EDIT TO ADD THE CENSUS STATISTICS WE USE
	esttab A B using "../output/table2.tex", replace ///
			mtitle("Not-weighted" "Weighted") ///
			cells(mean(fmt(3)) sd(par(( )) fmt(4))) label nonum f
			
restore

***********************************************
/* TABLE 3: AVERAGE MRS */
***********************************************

* PROBIT WITH AVERAGE INCOME
probit response_q avginc_q mob_q iir_q [pw=rakedwgt], vce(cluster id) nocons
margins, dydx(*) post

mat b = e(b)
mat V = vecdiag(e(V))

nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs}))  ///
	  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000) ///
	   , post

mat tmp = r(b)
mat coleq tmp = nlcom
mat b = b, tmp
mat tmp = vecdiag(r(V))
mat coleq tmp = nlcom
mat V = V, tmp
mat V = diag(V)
erepost b=b V=V

eststo probavg

* PROBIT WITH MEDIAN INCOME
probit response_q p90inc_q p50inc_q p10inc_q mob_q [pw=rakedwgt], vce(cluster id) nocons
margins, dydx(*) post

mat b = e(b)
mat V = vecdiag(e(V))

nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
	  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000) ///
	  , post 
	
mat tmp = r(b)
mat coleq tmp = nlcom
mat b = b, tmp
mat tmp = vecdiag(r(V))
mat coleq tmp = nlcom
mat V = V, tmp
mat V = diag(V)
erepost b=b V=V

eststo probmed

# del ;
esttab probavg probmed using "../output/table3.tex"
	, replace
	label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
	rename(p50inc_q inc avginc_q inc ) 
	coeflabels(inc "Middle Income" 
			   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
			   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
	cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
	nodepvar mtitles("Average" "Median") collabels(none) onecell
	;
# del cr

	
***********************************************
/* TABLE 4: VEIL CONDITION */
***********************************************
preserve
	foreach v in veil noveil {
		if "`v'"=="veil" loc name veil
		if "`v'"=="noveil" loc name noveil

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post

		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post

		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/1 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if veil==1
			replace grp = 2 if noveil==1
			}
		probit response_q i.grp#c.(avginc_q mob_q iir_q ) [pw=rakedwgt], vce(cluster id) nocons
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) 	, post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 2/2 {
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if veil==1
			replace grp = 2 if noveil==1
			}

		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q ) [pw=rakedwgt], vce(cluster id) nocons
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}
	
	# del ;
	esttab probavgveil probavgnoveil probmedveil probmednoveil using "../output/table4.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Veil" "No Veil" "Veil" "No Veil")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber
		;
	
	esttab test1 test2 
		using "../output/table4.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
restore

****************************************************************************************************************
/* Table 5: THEORETICAL AND EMPIRICAL SELF-INTEREST (INCOME CONDITION) */
****************************************************************************************************************	

preserve
		*** by income SHOULD WE DO IT WITH 20 and 80?
	cap drop bottominc
	cap drop middleinc
	cap drop topinc
	*keep if veil==1
	_pctile inc  [aw=raked], percentiles(20 80)
	gen bottominc = inc<`r(r1)'
	gen middleinc = inrange(inc,`r(r1)',`r(r2)')
	gen topinc = inc>`r(r2)'
	

	foreach v in bottominc middleinc topinc {
		
		if "`v'"=="bottominc" loc name bot
		if "`v'"=="middleinc" loc name mid
		if "`v'"=="topinc" loc name top

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if middleinc==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if topinc==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if topinc==1
			replace grp = 2 if middleinc==1
			}				
		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) , post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 4/6 {
		if "`m'"=="4" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if middleinc==1
			}
		if "`m'"=="5" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if topinc==1
			}		
		if "`m'"=="6" {
			cap drop grp
			gen grp = 1 if topinc==1
			replace grp = 2 if middleinc==1
			}	
		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) nocons
		*clogit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) group(id)
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}

	# del ;
	esttab probavgbot probavgmid probavgtop probmedbot probmedmid probmedtop using "../output/table5.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Bottom 20 Income" "Middle 60 Income" "Top 20 Income" "Bottom 20 Income" "Middle 60 Income" "Top 20 Income")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	
	esttab test1 test2 test3 test4 test5 test6
		using "../output/table5.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
restore	



****************************************************************************************************************
/* Table 6: PARTY CONDITION */
****************************************************************************************************************
preserve
	foreach v in party_dem party_rep party_ind {
		
		if "`v'"=="party_dem" loc name dem
		if "`v'"=="party_ind" loc name ind
		if "`v'"=="party_rep" loc name rep

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_rep==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_ind==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if party_rep==1
			replace grp = 2 if party_ind==1
			}				
		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) , post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 4/6 {
		if "`m'"=="4" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_rep==1
			}
		if "`m'"=="5" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_ind==1
			}		
		if "`m'"=="6" {
			cap drop grp
			gen grp = 1 if party_rep==1
			replace grp = 2 if party_ind==1
			}	
		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) nocons
		*clogit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) group(id)
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}

	# del ;
	esttab probavgdem probavgind probavgrep probmeddem probmedind probmedrep using "../output/table6.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Democrat" "Independent" "Republican" "Democrat" "Independent" "Republican")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	
	esttab test1 test2 test3 test4 test5 test6
		using "../output/table6.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
restore
	
	
****************************************************************************************************************
/* Table 7: ADAPTIVE MRS: MOBILITY ALL AND THEN BY PARTY , PREDICTORS OF THE MRS */
****************************************************************************************************************	
preserve
	gen ln_income = ln(inc)
	gen age=age_alt
	replace age=21 if age_alt==. & age_1824==1
	replace age=30 if age_alt==. & age_2534==1
	replace age=40 if age_alt==. & age_3544==1
	replace age=50 if age_alt==. & age_4554==1
	replace age=64 if age_alt==. & age_55pl==1
	label variable age "Age"

	gen All=1
	gen educ_hsless = educ_hs | educ_none
	gen educ_collplus = educ_4yr | educ_4yrplus
	gen educ_some = educ_2yr | educ_somecoll

	label variable educ_some "Some college"
	label variable educ_collplus "Bachelor or above"
	label variable party_dem "Democrat"
	label variable party_ind "Independent"
	label variable ln_income "Ln household income"
	label variable age_alt "Age"
	label variable gender_male "Male"
	label variable race_black "Black"
	label variable race_hispanic "Hispanic"
	label variable race_other "Other race"
	replace past=(past>0 & past!=.)
	label variable past "Has greater income than parents"
	replace belief_mob=(belief_mob>=3 & belief_mob!=.)
	label variable belief_mob "Believes upper mobility is common"
	label variable future "Believes children have a better future"

	keep if question==1
	tab mobMRS, gen(d_)

	// COLOQUE LÍMITE INFERIOR 0
	gen mobMRS1 = 0 if d_1==1
	gen mobMRS2 = 307.87820 if d_1==1
	replace mobMRS1 = 307.87820 if d_2==1
	replace mobMRS2 = 641.12316 if d_2==1
	replace mobMRS1 = 641.12316 if d_3==1
	replace mobMRS2 = 1034.21239 if d_3==1
	replace mobMRS1 = 1034.21239 if d_4==1
	replace mobMRS2 = 1547.80822 if d_4==1
	replace mobMRS1 = 1547.80822 if d_5==1
	replace mobMRS2 = 2316.45870 if d_5==1
	replace mobMRS1 = 2316.45870 if d_6==1
	replace mobMRS2 = 3736.73959 if d_6==1
	replace mobMRS1 = 3736.73959 if d_7==1
	replace mobMRS2 = 7781.35739 if d_7==1
	replace mobMRS1 = 7781.35739 if d_8==1
	replace mobMRS2 = . if d_8==1

	drop d_*

	tab incineqMRS, gen(d_)

	// COLOQUE LÍMITE INFERIOR 0
	gen incineqMRS1 = 0 if d_1==1
	gen incineqMRS2 = 369.656388 if d_1==1
	replace incineqMRS1 = 369.656388 if d_2==1
	replace incineqMRS2 = 769.7695792 if d_2==1
	replace incineqMRS1 = 769.7695792 if d_3==1
	replace incineqMRS2 = 1241.735268 if d_3==1
	replace incineqMRS1 = 1241.735268 if d_4==1
	replace incineqMRS2 = 1858.388158 if d_4==1
	replace incineqMRS1 = 1858.388158 if d_5==1
	replace incineqMRS2 = 2781.274426 if d_5==1
	replace incineqMRS1 = 2781.274426 if d_6==1
	replace incineqMRS2 = 4486.545895 if d_6==1
	replace incineqMRS1 = 4486.545895 if d_7==1
	replace incineqMRS2 = 9342.748178 if d_7==1
	replace incineqMRS1 = 9342.748178 if d_8==1
	replace incineqMRS2 = . if d_8==1

	drop d_*

	sum personalinc, d
	gen higher_income=(personalinc>r(p50)) if personalinc!=.
	gen lower_income=(personalinc<=r(p50)) if personalinc!=1
	label variable higher_income "Income higher than median"
	label variable lower_income "Income lower than median"

	_pctile inc [aw=raked], percentiles(20 80)
	gen bottominc = inc<`r(r1)'
	gen middleinc = inrange(inc,`r(r1)',`r(r2)')
	gen topinc = inc>`r(r2)' 
	lab var middleinc "Middle 60 Income"
	lab var topinc "Top 20 Income"

	foreach dv in mobMRS incineqMRS {
		//intreg `dv'1 `dv'2 educ_some educ_collplus party_dem party_ind higher_income age_2534 age_3544 age_4554 age_55pl gender_male race_black race_hispanic race_other past future belief_mob  [pw=rakedwgt] , r
		intreg `dv'1 `dv'2 educ_some educ_collplus party_dem party_ind middleinc topinc /*ln_income*/ age gender_male race_black race_hispanic race_other past belief_mob  [pw=rakedwgt] , r

		est sto int`dv'
		
		foreach g in party_dem party_ind party_rep {
			display ("`dv' + `g'")
			intreg `dv'1 `dv'2 educ_some educ_collplus middleinc topinc /*ln_income*/ age gender_male race_black race_hispanic race_other past belief_mob if `g'==1  [pw=rakedwgt], r
		est sto int`dv'`g'
	}
	}

	esttab  intmobMRS intmobMRSparty_dem intmobMRSparty_ind intmobMRSparty_rep intincineqMRS intincineqMRSparty_dem intincineqMRSparty_ind intincineqMRSparty_rep  using "../output/table7.tex", style(tex) replace ///
		cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
		label star(* 0.10 ** 0.05 *** .01) ///
		mtitles("All" "Dem" "Indep" "Rep")
		

	*** data that will be used later based on extreme values; we save as a local below called "extremes" but can change to dataset if want to run code in pieces
	ta mobMRS , gen(m_)
	gen mobmin = m_1==1
	gen mobmax = m_8==1
	ta incineqMRS, gen(i_)
	gen iirmin = i_1==1
	gen iirmax = i_8==1

	gen extreme1 = . 
	replace extreme1 = 2 if mobmin==1 
	replace extreme1 = 3 if mobmax==1 
	replace extreme1 = 4 if iirmin==1 
	replace extreme1 = 5 if iirmax==1
	replace extreme1 = 6 if mobmin==1 & iirmin==1 
	replace extreme1 = 7 if mobmax==1 & iirmax==1
	replace extreme1 = 8 if iirmax==1 & mobmin==1
	replace extreme1 = 9 if iirmin==1 & mobmax==1
	replace extreme1 = 1 if extreme1==.
	label define extreme1 1 "Normies" 2 "Mobility Min" 3 "Mobility Max" 4 "IIR Min" 5 "IIR Max" 6 "Mob+IIR Min" 7 "Mob+IIR Max" 8 "IIR Max+Mob Min" 9 "IIR Min+Mob Max", replace
	label values extreme1 extreme1

	gen extreme2 = inlist(extreme1,1,8,9)
	replace extreme2 = 2 if inlist(extreme1,2,4,6)
	replace extreme2 = 3 if inlist(extreme1,3,5,7)
	label define extreme2 1 "Normies" 2 "Min MRS" 3 "Max MRS" 
	label values extreme2 extreme2
	
	ta extreme2, gen(extreme_)
	foreach dv in mobMRS incineqMRS {
	intreg `dv'1 `dv'2 educ_some educ_collplus party_dem party_ind middleinc topinc /*ln_income*/ age gender_male race_black race_hispanic race_other past belief_mob  [pw=rakedwgt] , r
	}
	
	keep id group extreme1 extreme2 mobmin mobmax iirmin iirmax
	unique id 
	assert `r(N)'==`r(unique)'
	tempfile extremes
	save `extremes'
restore

****************************************************************************************************************
/* FIGURE 1: BASED ON THEORY, NO DATA */
****************************************************************************************************************	



****************************************************************************************************************
/* Figure 2: ISO-UTILITY for AVERAGE MRS */
****************************************************************************************************************		
	
// Isocurve p10
//probit prob inc mobil incineq [pw=peso], vce(cluster id) nocons
probit response_q p90inc_q p50inc_q p10inc_q mob_q  [pw=rakedwgt], vce(cluster id) nocons
matrix define beta_p50_p10=e(b)'

local a=beta_p50_p10[2,1]
local b=beta_p50_p10[3,1]

gen graph_p10=9.6+(_n-1)*(22.801-9.6)/100 if _n<=101

foreach i of numlist 59 66 76 {
	local U`i'=ln(`i')*`a'+ln(9.6)*`b'
	gen curve_p10_`i'=exp((`U`i''-`b'*ln(graph_p10))/`a')
	replace curve_p10_`i'=. if curve_p10_`i'<40
}

twoway (line curve_p10_59 graph_p10, sort)  (line curve_p10_66 graph_p10, sort)  (line curve_p10_76 graph_p10, sort), ///
	legend(off) xsize(3.5) ysize(3.5)  ytitle("Middle 60% income thousands", size(large)) xtitle("Bottom 20% Average Income", size(large))  ylabel(40(10)80, angle(hori)) scheme(s1mono) name(a, replace)  aspectratio(1)
graph export "../output/fig2a.pdf", replace as(pdf)

// Isocurve p90
*probit prob inc mobil incineq [pw=peso], vce(cluster id) nocons
probit response_q p90inc_q p50inc_q p10inc_q mob_q  [pw=rakedwgt], vce(cluster id) nocons
matrix define beta_p50_p90=e(b)'

local a=beta_p50_p90[2,1]
local b=beta_p50_p90[1,1]

gen graph_p90=125.651+(_n-1)*(208.496-125.651)/100 if _n<=101

foreach i of numlist 59 66 76 {
	local U`i'=ln(`i')*`a'+ln(125.651)*`b'
	gen curve_p90_`i'=exp((`U`i''-`b'*ln(graph_p90))/`a')
	replace curve_p90_`i'=. if curve_p90_`i'<40
}

twoway (line curve_p90_59 graph_p90, sort) (line curve_p90_66 graph_p90, sort) (line curve_p90_76 graph_p90, sort), ///
	legend(off) xsize(3.5) ysize(3.5)  ytitle("Middle 60% income thousands", size(large)) xtitle("Top 20% Average Income", size(large)) ylabel(40(10)80, angle(hori)) scheme(s1mono) name(b, replace)  aspectratio(1)

graph export "../output/fig2b.pdf", replace as(pdf)


// Isocurve mobility
probit response_q avginc_q mob_q iir_q [pw=rakedwgt], vce(cluster id) nocons
matrix define beta_p50_mob=e(b)'

// I use quadratic equation solution to get the isocurve
local a=beta_p50_mob[1,1]
local b=beta_p50_mob[2,1]

gen graph_mob=61.51+(_n-1)*(79.7-61.51)/100 if _n<=101

foreach i of numlist 71 79 92{
	local U`i'=ln(`i')*`a'+ln(61.51)*`b'
	gen curve_mob_`i'=exp((`U`i''-`b'*ln(graph_mob))/`a')
	replace curve_mob_`i'=. if curve_mob_`i'<50
}

twoway (line curve_mob_71 graph_mob, sort) (line curve_mob_79 graph_mob, sort)  (line curve_mob_92 graph_mob, sort), ///
	legend(off) xsize(3.5) ysize(3.5)  ytitle("Average income thousands", size(large)) xtitle("Income mobility", size(large)) ylabel(50(10)90, angle(hori)) scheme(s1mono)  name(c, replace)  aspectratio(1) //title(Income Mobility - Avg. Income)

graph export "../output/fig2c.pdf", replace as(pdf)


// Isocurve income equality
probit response_q avginc_q mob_q iir_q [pw=rakedwgt], vce(cluster id) nocons
matrix define beta_p50_ineq=e(b)'


// I use quadratic equation solution to get the isocurve
local a=beta_p50_ineq[1,1]
local b=beta_p50_ineq[3,1]

gen graph_ineq=15.12-(_n-1)*(15.12-8.42)/100 if _n<=101


foreach i of numlist 71 79 92{
	local U`i'=ln(`i')*`a'+ln(15.12)*`b'
	gen curve_ineq_`i'=exp((`U`i''-`b'*ln(graph_ineq))/`a')
}

twoway (line curve_ineq_71 graph_ineq, sort) (line curve_ineq_79 graph_ineq, sort)  (line curve_ineq_92 graph_ineq, sort), ///
	legend(off) xsize(3.5) ysize(3.5)  ytitle("Average income thousands", size(large)) xtitle("Income Inequality Ratio (90/10)", size(large)) ylabel(50(10)90, angle(hori)) scheme(s1mono)  name(d, replace) xscale(reverse) aspectratio(1) //title(Income Inequality - Avg. Income)

graph export "../output/fig2d.pdf", replace as(pdf)

****************************************************************************************************************
/* Figure 3: DISTRIBUTION OF MRS, BY PARTY */
****************************************************************************************************************		
preserve
	keep if question==1
	keep id incineqadapt mobadapt raked party_dem party_ind party_rep

	egen party = group(party_???)
	label define party 1 "Independent" 2 "Republican" 3 "Democrat"
	label values party party
	ta mobadapt, gen(mob_)
	ta incineqadapt, gen(inc_)
	replace raked = raked/4
	tempfile hold
	save `hold'
	
	collapse (mean) mob_? inc_? [aw=raked], by(party)
	tempfile party
	save `party'
	u `hold', clear
	collapse (mean) mob_? inc_? [aw=raked]
	append using `party'

	replace party = 99 if party==.

	reshape long mob_ inc_, i(party) j(mrs)
	reshape wide mob_ inc_, i(mrs) j(party)
	order mrs mob_1 mob_2 mob_3 inc_1 inc_2 inc_3
	rename inc_1 inc_ind
	rename mob_2 mob_rep
	rename mob_3 mob_dem
	rename inc_2 inc_rep
	rename inc_3 inc_dem
	rename mob_1 mob_ind

	rename mob_99 mob_all
	rename inc_99 inc_all

	foreach v in mob inc {
	foreach g in ind rep dem all {
	gsort -mrs
	gen cum`v'_`g' = sum(`v'_`g')
	gen `v'_`g'below = 1-cum`v'_`g' 
	replace `v'_`g'below = `v'_`g'below + `v'_`g'[_n+1]
	*drop cum`v'_`g'
	replace `v'_`g'below = 1 if mrs==8
	}
	}

	set scheme s1mono
	# del ;
	graph tw
		(line cuminc_ind mrs, lc(gray%50) lp(dot)) (line cuminc_rep mrs, lc(gray%50) lp(longdash)) (line cuminc_dem mrs, lc(gray%50) lp(dash)) (line cuminc_all mrs, lc(black%50) lw(thick))
		, xlab(1 "$0" 2 "$570" 3 "$1,006" 4 "$1,550"  5 "$2,320" 6 "$3,634" 7 "$6,915" 8 "$9,343", labsize(large) grid) ylab(0(.1)1,grid labsize(large)  angle(hori)) ytitle() xtitle("") xsca(reverse)
		leg(off) name(iir, replace) xsize(5) ysize(4)
	;
	# del cr
	graph export "../output/fig3a.pdf", replace as(pdf)	

	# del ;
	graph tw
		(line cummob_ind mrs, lc(gray%50) lp(dot)) (line cummob_rep mrs, lc(gray%50) lp(longdash)) (line cummob_dem mrs, lc(gray%50) lp(dash)) (line cummob_all mrs, lc(black%50) lw(thick))
		, xlab(1 "$0" 2 "$475" 3 "$834" 4 "$1,291" 5 "$1,932" 6 "$3,027" 7 "$5,759" 8 "$7,781",labsize(large)  grid) ylab(0(.1)1,grid labsize(large)  angle(hori)) ytitle() xtitle("")  xsca(reverse)
		leg(order(2 "Republican"  1 "Independent" 3 "Democrat" 4 "All")cols(1)pos(5)symxsize(*1)ring(0)size(large)) name(mob, replace) xsize(5) ysize(4)
	;
	# del cr
	graph export "../output/fig3b.pdf", replace as(pdf)

restore

preserve
	keep if question==1
	gen party_all = 1
	
	tempfile hold
	save `hold'
	
	foreach g in all dem rep ind {
		foreach u in mob incineq {
			u `hold', clear
			collapse (percent) id [aw=raked] if party_`g'==1, by(`u'MRS)
			gen party = "`g'"
			bys party (*MRS): gen order = _n
			rename id `u'pct
			tempfile `g'`u'
			save ``g'`u''
		}
	}
	
	u `allmob', clear
	append using `demmob'
	append using `indmob'
	append using `repmob'
	tempfile mob
	save `mob'
	
	u `allincineq'
	append using `demincineq'
	append using `indincineq'
	append using `repincineq'
	
	mer 1:1 party order using `mob'
	drop _merge
	
	*reshape wide incineqMRS incineqpct mobMRS mobpct, i(order) j(party) string
	gen party_num = 1 if party=="all"
	replace party_num = 2 if party=="dem"
	replace party_num = 3 if party=="ind"
	replace party_num = 4 if party=="rep"
	
	set scheme burd
	heatplot incineqpct order party_num, ///	
		colors(Greys    , intensity(.9) opacity(75)) p(lc(black%10) lalign(center)) legend(off) values(size(medlarge) format(%9.2f))  cuts(5 7 9 11 13 24 26 28  ) ///
		ylab(1 "$0" 2 "$570" 3 "$1,006" 4 "$1,550" 5 "$2,320" 6 "$3,534" 7 "$6,915" 8 "$9,343", nogrid labsize(large)) xlab(1 "All" 2 "Democrat" 3 "Independent" 4 "Republican" , nogrid)  plotregion(m(zero)) discrete ///
		xtitle("") ytitle("") xsize(5) ysize(4) statistic(asis) yscale(noline) xscale(noline) name(inc, replace)
	graph export "../output/fig3c.pdf", replace as(pdf)		

		
	heatplot mobpct order party_num, ///	
		colors(Greys, intensity(.9) opacity(75)) p(lc(black%10) lalign(center)) legend(off) values(size(medlarge) format(%9.2f))  cuts(5 7 9 11 13 24 26 28 ) ///
		ylab(1 "$0" 2 "$475" 3 "$838" 4 "$1,291" 5 "$1,932" 6 "$3,027" 7 "$5,759" 8 "$7,781", nogrid labsize(large)) xlab(1 "All" 2 "Democrat" 3 "Independent" 4 "Republican" , nogrid)  plotregion(m(zero)) discrete ///
		xtitle("") ytitle("") xsize(5) ysize(4) statistic(asis) yscale(noline) xscale(noline) name(mob, replace)
	graph export "../output/fig3d.pdf", replace as(pdf)		
	
restore	

****************************************************************************************************************
/* FIGURE 4: JOINT DISTRIBUTION OF MRS , ALL AND BY PARTY*/
****************************************************************************************************************		
preserve
	keep if question==1
	gen person = 1
	foreach v in mobadapt incineqadapt {
		replace `v' = 2 if inlist(`v',2,3)
		replace `v' = 3 if inlist(`v',4,5)
		replace `v' = 4 if inlist(`v',6,7)
		replace `v' = 5 if `v'==8
	}
	bys mobadapt : egen medmobMRS = median(mobMRS)
	bys incineqadapt : egen mediirMRS = median(incineqMRS)
	drop mobMRS incineqMRS
	rename medmobMRS mobMRS
	rename mediirMRS iirMRS
	egen adapgrp = group(mobadapt incineqadapt )
	replace raked = raked/4
	tempfile hold
	save `hold'
	collapse (sum) person (firstnm) mobMRS iirMRS [aw=raked], by(adapgrp)
	gen pct = person/1249
	gen party = 99
	tempfile all
	save `all'
	
	u `hold', clear
	gen party = 1 if party_dem==1
	replace party = 2 if party_ind==1
	replace party = 3 if party_rep==1
	collapse (sum) person (firstnm) mobMRS iirMRS [aw=raked], by(adapgrp party)
	append using `all'
	tsset party adapgr
	tsfill, full
	replace person = 0 if person==.
	forval i = 1/25 {
		levelsof mobMRS if adapgr==`i' & mobMRS!=., loc(temp)
		replace mobMRS = `temp' if mobMRS==. & adapgr==`i'
		levelsof iirMRS if adapgr==`i' & iirMRS!=., loc(temp)
		replace iirMRS = `temp' if iirMRS==. & adapgr==`i'
	}
	forval p =1/3 {
		sum person if party==`p'
		replace pct = person/`r(sum)' if party==`p'
		}
	
	tostring mobMRS, replace format(%3.0f) force
	tostring iirMRS, replace format(%3.0f) force
	destring mobMRS, replace
	destring iirMRS, replace
	replace pct = pct*100
	sort party adapgr
	egen iirsort = seq(), from(1) to(5) 
	egen mobsort = seq(), from(1) to(5) block(5)
	tostring mobMRS, replace format(%3.0f) force
	tostring iirMRS, replace format(%3.0f) force
	labmask mobsort, val(mobMRS)
	labmask iirsort, val(iirMRS)
	heatplot pct mobsort iirsort if party==99, colors(Greys    , intensity(.9) opacity(75)) p(lc(black%10) lalign(center)) legend(off) values(size(medlarge) format(%9.2f))  cuts(2 3 4 5 7 12 ) ///
		ytitle("Mobility MRS", size(large)) xtitle("IIR MRS", size(large)) name(all, replace) plotregion(m(zero)) ylab(1 "$0" 2 "$838" 3 "$1,932" 4 "$5,759" 5 "$7,781", labsize(large)) xlab(1 "$0" 2 "$1,006" 3 "$2,320" 4 "$6,915" 5 "$9,343", labsize(large)) discrete
	graph export "../output/fig4a.pdf", replace as(pdf) 
	heatplot pct mobsort iirsort if party==1, colors(Greys    , intensity(.9) opacity(75)) p(lc(black%10) lalign(center)) legend(off) values(size(medlarge) format(%9.2f))  cuts(2 3 4 5 7 12 ) ///
			ytitle("Mobility MRS", size(large)) xtitle("IIR MRS", size(large)) name(dem, replace) plotregion(m(zero)) ylab(1 "$0" 2 "$838" 3 "$1,932" 4 "$5,759" 5 "$7,781", labsize(large)) xlab(1 "$0" 2 "$1,006" 3 "$2,320" 4 "$6,915" 5 "$9,343", labsize(large))		discrete
	graph export "../output/fig4b.pdf", replace as(pdf)	
	heatplot pct mobsort iirsort if party==2, colors(Greys    , intensity(.9) opacity(75)) p(lc(black%10) lalign(center)) legend(off) values(size(medlarge) format(%9.2f))  cuts(2 3 4 5 7 12 ) ///
			ytitle("Mobility MRS", size(large)) xtitle("IIR MRS", size(large)) name(ind, replace) plotregion(m(zero)) ylab(1 "$0" 2 "$838" 3 "$1,932" 4 "$5,759" 5 "$7,781", labsize(large)) xlab(1 "$0" 2 "$1,006" 3 "$2,320" 4 "$6,915" 5 "$9,343", labsize(large))		 discrete	
	graph export "../output/fig4c.pdf", replace as(pdf)	
	heatplot pct mobsort iirsort if party==3, colors(Greys    , intensity(.9) opacity(75)) p(lc(black%10) lalign(center)) legend(off) values(size(medlarge) format(%9.2f))  cuts(2 3 4 5 7 12 ) ///
			ytitle("Mobility MRS", size(large)) xtitle("IIR MRS", size(large)) name(rep, replace) plotregion(m(zero)) ylab(1 "$0" 2 "$838" 3 "$1,932" 4 "$5,759" 5 "$7,781", labsize(large)) xlab(1 "$0" 2 "$1,006" 3 "$2,320" 4 "$6,915" 5 "$9,343", labsize(large))		discrete	
	graph export "../output/fig4d.pdf", replace as(pdf)		
restore

****************************************************************************************************************
/* Figures A.1 - A.5 ARE SCREENSHOTS FROM SURVEY */
****************************************************************************************************************		

****************************************************************************************************************
/* APPENDIX TABLE A.1: DIAGNOSTIC QUESTIONS PERFORMANCE DETAILS*/
****************************************************************************************************************		

eststo q1: reg diag_q i.question [aw=raked], robust 

preserve
	gen ln_income = ln(inc)
	/*gen top_income=(inc==175000)
	replace ln_income=0 if inc==175000
	label variable top_income "Household income $\geq$ 175k"
	*/
	gen age=age_alt
	replace age=21 if age_alt==. & age_1824==1
	replace age=30 if age_alt==. & age_2534==1
	replace age=40 if age_alt==. & age_3544==1
	replace age=50 if age_alt==. & age_4554==1
	replace age=64 if age_alt==. & age_55pl==1
	label variable age "Age"

	gen All=1
	gen educ_hsless = educ_hs | educ_none
	gen educ_collplus = educ_4yr | educ_4yrplus
	gen educ_some = educ_2yr | educ_somecoll

	label variable educ_some "Some college"
	label variable educ_collplus "Bachelor or above"
	label variable party_dem "Democrat"
	label variable party_ind "Independent"
	label variable ln_income "Ln household income"
	label variable age_alt "Age"
	label variable gender_male "Male"
	label variable race_black "Black"
	label variable race_hispanic "Hispanic"
	label variable race_other "Other race"
	replace past=(past>0 & past!=.)
	label variable past "Has greater income than parents"
	replace belief_mob=(belief_mob>=3 & belief_mob!=.)
	label variable belief_mob "Believes upper mobility is common"
	label variable future "Believes children have a better future"

	keep if question==1


	sum personalinc, d
	gen higher_income=(personalinc>r(p50)) if personalinc!=.
	gen lower_income=(personalinc<=r(p50)) if personalinc!=1
	label variable higher_income "Income higher than median"
	label variable lower_income "Income lower than median"

	_pctile inc [aw=raked], percentiles(20 80)
	gen bottominc = inc<`r(r1)'
	gen middleinc = inrange(inc,`r(r1)',`r(r2)')
	gen topinc = inc>`r(r2)' 
	lab var middleinc "Middle 60 Income"
	lab var topinc "Top 20 Income"
	
	eststo q_mult: reg diag_pctright  educ_some educ_collplus party_dem party_ind middleinc topinc /*ln_income*/ age gender_male race_black race_hispanic race_other past belief_mob   [aw=raked], robust

# del ;
	esttab q1 q_mult using "../output/tablea1.tex"
		, replace
		label  
		coeflabels(_cons "Percent Right" 				   )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Q1" "Q2" "Q3" "Q4" "All Questions", pattern(1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
# del cr
restore

****************************************************************************************************************
/* APPENDIX TABLE A.2: AVERAGE MRS FOR DIAGNOSTIC CORRECT*/
****************************************************************************************************************		

preserve
	gen diaghigh = diag_pctright==1
	gen diagmid  = diag_pctright==.75
	gen diaglow  = diag_pctright<.75

	ta diaglow party_rep [aw=raked]
	
	reg diaglow party_dem party_rep [aw=raked]
	reg diaghigh party_dem party_rep [aw=raked]
	foreach v in diaghigh diagmid diaglow {
		
		if "`v'"=="diaghigh" loc name high
		if "`v'"=="diagmid" loc name mid
		if "`v'"=="diaglow" loc name low

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if diaghigh==1
			replace grp = 2 if diagmid==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if diaghigh==1
			replace grp = 2 if diaglow==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if diagmid==1
			replace grp = 2 if diaglow==1
			}				
		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) , post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 4/6 {
		if "`m'"=="4" {
			cap drop grp
			gen grp = 1 if diaghigh==1
			replace grp = 2 if diagmid==1
			}
		if "`m'"=="5" {
			cap drop grp
			gen grp = 1 if diaghigh==1
			replace grp = 2 if diaglow==1
			}		
		if "`m'"=="6" {
			cap drop grp
			gen grp = 1 if diagmid==1
			replace grp = 2 if diaglow==1
			}	
		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) nocons
		*clogit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) group(id)
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}

	# del ;
	esttab probavghigh probavgmid probavglow probmedhigh probmedmid probmedlow using "../output/tablea2.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Diag=1" "Diag=.75" "Diag<.75" "Diag=1" "Diag=.75" "Diag<.75")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	
	esttab test1 test2 test3 test4 test5 test6
		using "../output/tablea2.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
restore


****************************************************************************************************************
/* APPENDIX TABLE A.3: AVERAGE MRS BY TIME TO COMPLETION */
****************************************************************************************************************
preserve
	_pctile duration [aw=raked], percentiles(33 66)
	gen bottomtime = duration<`r(r1)'
	gen middletime = inrange(duration,`r(r1)',`r(r2)')
	gen toptime = duration>`r(r2)'

	foreach v in bottomtime middletime toptime {
		
		if "`v'"=="bottomtime" loc name bot
		if "`v'"=="middletime" loc name mid
		if "`v'"=="toptime" loc name top

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if bottomtime==1
			replace grp = 2 if middletime==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if bottomtime==1
			replace grp = 2 if toptime==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if middletime==1
			replace grp = 2 if toptime==1
			}				
		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) , post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 4/6 {
		if "`m'"=="4" {
			cap drop grp
			gen grp = 1 if bottomtime==1
			replace grp = 2 if middletime==1
			}
		if "`m'"=="5" {
			cap drop grp
			gen grp = 1 if bottomtime==1
			replace grp = 2 if toptime==1
			}		
		if "`m'"=="6" {
			cap drop grp
			gen grp = 1 if middletime==1
			replace grp = 2 if toptime==1
			}				
		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) nocons
		*clogit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) group(id)
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}

	# del ;
	esttab probavgbot probavgmid probavgtop probmedbot probmedmid probmedtop using "../output/tablea3.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Fast" "Middle" "Slow" "Fast" "Middle" "Slow")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	
	esttab test1 test2 test3 test4 test5 test6
		using "../output/tablea3.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
restore

****************************************************************************************************************
/* APPENDIX TABLE A.4: PERCENTILES USED FOR WTP CALCULATION*/
****************************************************************************************************************		

**see .do file "replication_randomization_values.do" 

****************************************************************************************************************
/* APPENDIX TABLE A.5: AVERAGE MRS MARGINAL EFFECTS */
****************************************************************************************************************		
** NOTE THAT THESE RESULTS WERE GENERATED AND OUTPUT TO TABLE 3; PAPER MOVES MARGINAL EFFECTS TO APPENDIX FOR SPACE

****************************************************************************************************************
/* APPENDIX TABLE A.6: VEIL CONDITION, MARGINAL EFFECTS AND TEST STATISTICS */
****************************************************************************************************************		
** NOTE THAT THESE RESULTS WERE GENERATED AND OUTPUT TO TABLE 4; PAPER MOVES MARGINAL EFFECTS AND TEST STATISTICS TO APPENDIX FOR SPACE

****************************************************************************************************************
/* APPENDIX TABLE A.7: HOUSEHOLD INCOME CONDITION, MARGINAL EFFECTS, MRS, WTP, AND TEST STATISTICS */
****************************************************************************************************************		
** NOTE THAT THESE RESULTS WERE GENERATED AND OUTPUT TO TABLE 5; PAPER MOVES MODEL RESULTS TO APPENDIX FOR SPACE

****************************************************************************************************************
/* APPENDIX TABLE A.8: PARTY CONDITION, MARGINAL EFFECTS, MARGINAL EFFECTS AND WTP*/
****************************************************************************************************************		
** NOTE THAT THESE RESULTS WERE GENERATED AND OUTPUT TO TABLE 6; PAPER MOVES MODEL RESULTS TO APPENDIX FOR SPACE


****************************************************************************************************************
/* APPENDIX TABLE A.9: AVERAGE MRS WEIGHTED/UNWEIGHTED AND BY SAMPLES*/
****************************************************************************************************************		
preserve
	loc i = 0
	foreach d in preferred_sampleRR_uniwts full_sampleRR_uniwts  preferred_sampleRR_uniwts_plus preferred_sampleRR_uniwts_plus_educ {
	loc ++i
	u "`d'", clear
	label var avginc_q "Middle Income" 
	label var p50inc_q "Middle Income" 
	label var mob_q "Income Mobility"
	label var iir_q "Income Inequality Ratio"
	label var p10inc_q "Income 10th Percentile"
	label var p90inc_q "Income 90th Percentile"

	*if inlist("`d'","preferred_sampleRR_uniwts","full_sampleRR_uniwts") loc wt "[pw=rakedwgt]"
	*else loc wt ""
	loc wt "[pw=rakedwgt]"	



	* PROBIT WITH AVERAGE INCOME
	probit response_q avginc_q mob_q iir_q `wt', vce(cluster id) nocons
	margins, dydx(*) post

	mat b = e(b)
	mat V = vecdiag(e(V))

	nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
		  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

	mat tmp = r(b)
	mat coleq tmp = nlcom
	mat b = b, tmp
	mat tmp = vecdiag(r(V))
	mat coleq tmp = nlcom
	mat V = V, tmp
	mat V = diag(V)
	erepost b=b V=V

	eststo avg`i'

	* PROBIT WITH MEDIAN INCOME
	probit response_q p90inc_q p50inc_q p10inc_q mob_q `wt' , vce(cluster id) nocons
	margins, dydx(*) post

	mat b = e(b)
	mat V = vecdiag(e(V))

	nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
		  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post 

	mat tmp = r(b)
	mat coleq tmp = nlcom
	mat b = b, tmp
	mat tmp = vecdiag(r(V))
	mat coleq tmp = nlcom
	mat V = V, tmp
	mat V = diag(V)
	erepost b=b V=V

	eststo med`i'
	}
restore

# del ;
esttab avg1 avg2 avg3 avg4 med1 med2 med3  med4 using "../output/tablea9.tex"
	, replace
	label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
	rename(p50inc_q inc avginc_q inc ) 
	coeflabels(inc "Middle Income" 
			   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
			   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
	cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
	nodepvar mgroups("Average" "Median", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Samp 1 Wtd" "Samp 1" "Samp 2 Wtd" "Samp 2" "Samp 1 Wtd" "Samp 1" "Samp 2 Wtd" "Samp 2" )  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
	;
# del cr



****************************************************************************************************************
/* APPENDIX TABLE A.10, A.11, A.12: AVERAGE MRS PARTY-BY-INCOME */
****************************************************************************************************************		

preserve
	cap drop bottominc
	cap drop middleinc
	cap drop topinc
	_pctile inc [aw=raked], percentiles(20 80)
	gen bottominc = inc<`r(r1)'
	gen middleinc = inrange(inc,`r(r1)',`r(r2)')
	gen topinc = inc>`r(r2)'
	tempfile hold
	save `hold'
	loc i = 9
	foreach v1 in party_dem party_rep party_ind {
		loc ++i
		u `hold', clear
		keep if `v1'==1
		if "`v'"=="party_dem" loc name1 dem
		if "`v'"=="party_ind" loc name1 ind
		if "`v'"=="party_rep" loc name1 rep
	foreach v in bottominc middleinc topinc {
		
		if "`v'"=="bottominc" loc name bot
		if "`v'"=="middleinc" loc name mid
		if "`v'"=="topinc" loc name top

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if middleinc==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if topinc==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if topinc==1
			replace grp = 2 if middleinc==1
			}				
		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) , post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 4/6 {
		if "`m'"=="4" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if middleinc==1
			}
		if "`m'"=="5" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if topinc==1
			}		
		if "`m'"=="6" {
			cap drop grp
			gen grp = 1 if topinc==1
			replace grp = 2 if middleinc==1
			}	
		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) nocons
		*clogit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) group(id)
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}

	# del ;
	esttab probavgbot probavgmid probavgtop probmedbot probmedmid probmedtop using "../output/tablea`i'.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Bottom 20 Income" "Middle 60 Income" "Top 20 Income" "Bottom 20 Income" "Middle 60 Income" "Top 20 Income")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	
	esttab test1 test2 test3 test4 test5 test6
		using "../output/tablea`i'.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
	}
restore


***********************************************
/* APPENDIX TABLE A.13: MRS AND WTP FOR INCOME EQUALITY AGAINST INCOME MOBILITY */
***********************************************

* PROBIT WITH AVERAGE INCOME
probit response_q avginc_q mob_q iir_q [pw=rakedwgt], vce(cluster id) nocons
margins, dydx(*) post

mat b = e(b)
mat V = vecdiag(e(V))

nlcom (Rawls_mrs: -1*(_b[mob_q]/_b[iir_q] * ${iirmrs}/${mobmrs}))	///			
	  (Rawls_wtp: -1*(_b[mob_q]/_b[iir_q] * ${iirmrs}/${mobmrs}*${mobpct}/${iirpct})) ///
	  , post

mat tmp = r(b)
mat coleq tmp = nlcom
mat b = b, tmp
mat tmp = vecdiag(r(V))
mat coleq tmp = nlcom
mat V = V, tmp
mat V = diag(V)
erepost b=b V=V

eststo probavg

foreach v in dem rep ind  {
	* PROBIT WITH AVERAGE INCOME
	probit response_q avginc_q mob_q iir_q [pw=rakedwgt] if party_`v'==1, vce(cluster id) nocons
	margins, dydx(*) post

	mat b = e(b)
	mat V = vecdiag(e(V))

	nlcom (Rawls_mrs: -1*(_b[mob_q]/_b[iir_q] * ${iirmrs}/${mobmrs}))	///			
		  (Rawls_wtp: -1*(_b[mob_q]/_b[iir_q] * ${iirmrs}/${mobmrs}*${mobpct}/${iirpct})) ///
		  , post

	mat tmp = r(b)
	mat coleq tmp = nlcom
	mat b = b, tmp
	mat tmp = vecdiag(r(V))
	mat coleq tmp = nlcom
	mat V = V, tmp
	mat V = diag(V)
	erepost b=b V=V

	eststo probavg_`v'
}
	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_rep==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_ind==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if party_rep==1
			replace grp = 2 if party_ind==1
			}				

		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		
		nlcom (Rawls_mrs: (-1*(_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#iir_q] * ${iirmrs}/${mobmrs})) - (-1*(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#iir_q] * ${iirmrs}/${mobmrs})))	///			
			, post		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar Rawls_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		eststo test`m'
	}

# del ;
esttab probavg probavg_dem probavg_ind probavg_rep  using "../output/tablea13.tex"
	, replace
	label order(inc mob_q iir_q Rawls_mrs Rawls_wtp )   
	rename(avginc_q inc ) 
	coeflabels(inc "Middle Income" 
			   Rawls_mrs "Percentage of Mobility for 1-unit of IIR"
			   Rawls_wtp "10-Percentile of Mobility for 10-Percentile of IIR")
	cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
	nodepvar mtitles("Average") collabels(none) onecell
	;
# del cr
# del ;
esttab test1 test2 test3 using "../output/tablea13.tex"
	, append
	scalars("Rawls_test Percentage of Mobility for 1-unit of IIR") 
	mtitles("Average" )
	rename(Rawls_test "Percentage of Mobility for 1-unit of IIR" )
	drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
;

# del cr


****************************************************************************************************************
/* APPENDIX TABLE A.14 , A.15: EXTREMISTS DIAGNOSTIC PERFORMANCE AND DESCRIPTIVE STATISTICS */
****************************************************************************************************************		
mer m:1 id using `extremes' , gen(_extreme)
ta extreme2, gen(extreme_)

preserve
	gen ln_income = ln(inc)
	/*gen top_income=(inc==175000)
	replace ln_income=0 if inc==175000
	label variable top_income "Household income $\geq$ 175k"
	*/
	gen age=age_alt
	replace age=21 if age_alt==. & age_1824==1
	replace age=30 if age_alt==. & age_2534==1
	replace age=40 if age_alt==. & age_3544==1
	replace age=50 if age_alt==. & age_4554==1
	replace age=64 if age_alt==. & age_55pl==1
	label variable age "Age"

	gen All=1
	gen educ_hsless = educ_hs | educ_none
	gen educ_collplus = educ_4yr | educ_4yrplus
	gen educ_some = educ_2yr | educ_somecoll

	label variable educ_some "Some college"
	label variable educ_collplus "Bachelor or above"
	label variable party_dem "Democrat"
	label variable party_ind "Independent"
	label variable ln_income "Ln household income"
	label variable age_alt "Age"
	label variable gender_male "Male"
	label variable race_black "Black"
	label variable race_hispanic "Hispanic"
	label variable race_other "Other race"
	replace past=(past>0 & past!=.)
	label variable past "Has greater income than parents"
	replace belief_mob=(belief_mob>=3 & belief_mob!=.)
	label variable belief_mob "Believes upper mobility is common"
	label variable future "Believes children have a better future"

	keep if question==1

	sum personalinc, d
	gen higher_income=(personalinc>r(p50)) if personalinc!=.
	gen lower_income=(personalinc<=r(p50)) if personalinc!=1
	label variable higher_income "Income higher than median"
	label variable lower_income "Income lower than median"

	_pctile inc [aw=raked], percentiles(20 80)
	gen bottominc = inc<`r(r1)'
	gen middleinc = inrange(inc,`r(r1)',`r(r2)')
	gen topinc = inc>`r(r2)' 
	lab var middleinc "Middle 60 Income"
	lab var topinc "Top 20 Income"
	
	label define extreme1 1 "Normies (n=496)" 2 "Mobility Min (n=62)" 3 "Mobility Max (n=63)" 4 "IIR Min (n=152)" 5 "IIR Max (n=103)" 6 "Mob+IIR Min (n=109)" 7 "Mob+IIR Max (n=183)" 8 "IIR Max+Mob Min (n=23)" 9 "IIR Min+Mob Max (n=58)", replace
	label values extreme1 extreme1
	
	eststo diag: reg diag_pctright i.extreme1 [aw=raked] if question==1, robust 

	# del ;
	esttab diag using "../output/tablea14.tex"
		, replace
		label coeflabels(_cons "Non-Extreme (n=496)" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar 
		 alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	# del cr
	cap est clear
	mlogit extreme2 educ_some educ_collplus party_dem party_ind middleinc topinc age gender_male race_black race_hispanic race_other past belief_mob  [pw=rakedwgt] , r nolog
	estadd prchange, split
	esttab using "../output/tablea15.tex", replace main(dc) not noobs mtitles label 	style(tex) star(* 0.10 ** 0.05 *** 0.01) 
restore	
	
	
****************************************************************************************************************
/* Table A.16: AVERAGE MRS by LEXICOGRAPHIC PREFERENCES CONDITION */
****************************************************************************************************************	

	
preserve
	foreach v in extreme_1 extreme_2 extreme_3 {
		
		if "`v'"=="extreme_1" loc name norm
		if "`v'"=="extreme_2" loc name minmrs
		if "`v'"=="extreme_3" loc name maxmrs

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if extreme_1==1
			replace grp = 2 if extreme_2==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if extreme_1==1
			replace grp = 2 if extreme_3==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if extreme_2==1
			replace grp = 2 if extreme_3==1
			}				
		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) , post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 4/6 {
		if "`m'"=="4" {
			cap drop grp
			gen grp = 1 if extreme_1==1
			replace grp = 2 if extreme_2==1
			}
		if "`m'"=="5" {
			cap drop grp
			gen grp = 1 if extreme_1==1
			replace grp = 2 if extreme_3==1
			}		
		if "`m'"=="6" {
			cap drop grp
			gen grp = 1 if extreme_2==1
			replace grp = 2 if extreme_3==1
			}	
		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) nocons
		*clogit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) group(id)
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}

	# del ;
	esttab probavgnorm probavgminmrs probavgmaxmrs probmednorm probmedminmrs probmedmaxmrs using "../output/tablea16.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Non-Extreme" "Min MRS" "Max MRS" "Non-Extreme" "Min MRS" "Max MRS")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	
	esttab test1 test2 test3 test4 test5 test6
		using "../output/tablea16.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
restore	

****************************************************************************************************************
/* Appendix Table A.17: PARTY CONDITION minus LEXICOGRAPHIC PREFERENCES*/
****************************************************************************************************************
preserve
	keep if extreme_1==1
	foreach v in party_dem party_rep party_ind {
		
		if "`v'"=="party_dem" loc name dem
		if "`v'"=="party_ind" loc name ind
		if "`v'"=="party_rep" loc name rep

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_rep==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_ind==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if party_rep==1
			replace grp = 2 if party_ind==1
			}				
		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) , post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 4/6 {
		if "`m'"=="4" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_rep==1
			}
		if "`m'"=="5" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_ind==1
			}		
		if "`m'"=="6" {
			cap drop grp
			gen grp = 1 if party_rep==1
			replace grp = 2 if party_ind==1
			}	
		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) nocons
		*clogit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) group(id)
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}

	# del ;
	esttab probavgdem probavgind probavgrep probmeddem probmedind probmedrep using "../output/tablea17.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Democrat" "Independent" "Republican" "Democrat" "Independent" "Republican")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	
	esttab test1 test2 test3 test4 test5 test6
		using "../output/tablea17.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
restore

****************************************************************************************************************
/* APPENDIX Table A.18: DIAGNOSTIC PERFORMANCE WITH EDUCATION SUPPLEMENT */
****************************************************************************************************************	

u "preferred_sampleRR_uniwts_plus_educ", clear		// here we call in the data that includes the second sample collection, what we refer to as the education supplement
*u "undereducsampRR", clear
** data stuff
cap drop _one
gen _one = 1

gen noveil = veil==0
sum personalinc,d
gen highinc = 1 if personalinc>=`r(p50)'
gen lowinc = 1 if personalinc<=`r(p50)'

* set these here, allows us to change inc from median to mean 
global incmedmrs  59.339 	// median 
global incmrs  71.419	// this is the median of the mean (the other statistics use the median as well)
global mobmrs  68.26
global iirmrs  11.5
global primrs 15
global elimrs 163.384

global pripct 1468.567	// based on linear regression of percentile against bottom 20 income
global elipct 9770.1	// based on linear regression of percentile against top 20 income
global mobpct 2.054		// based on linear regression of percentile against mobility 
global iirpct 1.12088		// based on linear regression of percentile against IIR

gen young = age_1824 ==1 | age_2534==1 | age_3544==1
gen old   = age_4554 ==1 | age_55pl==1
foreach v in p10socB_q p50socB_q p90socB_q avgincsocB_q p10socA_q p50socA_q p90socA_q avgincsocA_q {
	replace `v' = `v'*1000
	}
gen p10incdiff = ln(inc/p10socB_q)
gen p50incdiff = ln(inc/p50socB_q)
gen p90incdiff = ln(inc/p90socB_q)
gen avgincdiff = ln(inc/avgincsocB_q)

label var avginc_q "Middle Income" 
label var p50inc_q "Middle Income" 
label var mob_q "Income Mobility"
label var iir_q "Income Inequality Ratio"
label var p10inc_q "Income 10th Percentile"
label var p90inc_q "Income 90th Percentile"

graph set window fontface "Times New Roman"

eststo q1: reg diag_q i.question [aw=raked], robust 

preserve
	gen ln_income = ln(inc)
	/*gen top_income=(inc==175000)
	replace ln_income=0 if inc==175000
	label variable top_income "Household income $\geq$ 175k"
	*/
	gen age=age_alt
	replace age=21 if age_alt==. & age_1824==1
	replace age=30 if age_alt==. & age_2534==1
	replace age=40 if age_alt==. & age_3544==1
	replace age=50 if age_alt==. & age_4554==1
	replace age=64 if age_alt==. & age_55pl==1
	label variable age "Age"

	gen All=1
	gen educ_hsless = educ_hs | educ_none
	gen educ_collplus = educ_4yr | educ_4yrplus
	gen educ_some = educ_2yr | educ_somecoll

	label variable educ_some "Some college"
	label variable educ_collplus "Bachelor or above"
	label variable party_dem "Democrat"
	label variable party_ind "Independent"
	label variable ln_income "Ln household income"
	label variable age_alt "Age"
	label variable gender_male "Male"
	label variable race_black "Black"
	label variable race_hispanic "Hispanic"
	label variable race_other "Other race"
	replace past=(past>0 & past!=.)
	label variable past "Has greater income than parents"
	replace belief_mob=(belief_mob>=3 & belief_mob!=.)
	label variable belief_mob "Believes upper mobility is common"
	label variable future "Believes children have a better future"

	keep if question==1


	sum personalinc, d
	gen higher_income=(personalinc>r(p50)) if personalinc!=.
	gen lower_income=(personalinc<=r(p50)) if personalinc!=1
	label variable higher_income "Income higher than median"
	label variable lower_income "Income lower than median"

	_pctile inc [aw=raked], percentiles(20 80)
	gen bottominc = inc<`r(r1)'
	gen middleinc = inrange(inc,`r(r1)',`r(r2)')
	gen topinc = inc>`r(r2)' 
	lab var middleinc "Middle 60 Income"
	lab var topinc "Top 20 Income"
	
	eststo q_mult: reg diag_pctright  educ_some educ_collplus party_dem party_ind middleinc topinc /*ln_income*/ age gender_male race_black race_hispanic race_other past belief_mob   [aw=raked], robust

# del ;
	esttab q1 q_mult using "../output/tablea18.tex"
		, replace
		label  
		coeflabels(_cons "Percent Right" 				   )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Q1" "Q2" "Q3" "Q4" "All Questions", pattern(1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
# del cr
restore

***********************************************
/* APPENDIX TABLE A.19: AVERAGE MRS WITH THE EDUCATION SUPPLEMENT*/
***********************************************

u "preferred_sampleRR_uniwts_plus_educ", clear		// here we call in the data that includes the second sample collection, what we refer to as the education supplement
*u "undereducsampRR", clear
** data stuff
cap drop _one
gen _one = 1

gen noveil = veil==0
sum personalinc,d
gen highinc = 1 if personalinc>=`r(p50)'
gen lowinc = 1 if personalinc<=`r(p50)'

* set these here, allows us to change inc from median to mean 
global incmedmrs  59.339 	// median 
global incmrs  71.419	// this is the median of the mean (the other statistics use the median as well)
global mobmrs  68.26
global iirmrs  11.5
global primrs 15
global elimrs 163.384

global pripct 1468.567	// based on linear regression of percentile against bottom 20 income
global elipct 9770.1	// based on linear regression of percentile against top 20 income
global mobpct 2.054		// based on linear regression of percentile against mobility 
global iirpct 1.12088		// based on linear regression of percentile against IIR

gen young = age_1824 ==1 | age_2534==1 | age_3544==1
gen old   = age_4554 ==1 | age_55pl==1
foreach v in p10socB_q p50socB_q p90socB_q avgincsocB_q p10socA_q p50socA_q p90socA_q avgincsocA_q {
	replace `v' = `v'*1000
	}
gen p10incdiff = ln(inc/p10socB_q)
gen p50incdiff = ln(inc/p50socB_q)
gen p90incdiff = ln(inc/p90socB_q)
gen avgincdiff = ln(inc/avgincsocB_q)

label var avginc_q "Middle Income" 
label var p50inc_q "Middle Income" 
label var mob_q "Income Mobility"
label var iir_q "Income Inequality Ratio"
label var p10inc_q "Income 10th Percentile"
label var p90inc_q "Income 90th Percentile"

graph set window fontface "Times New Roman"

* PROBIT WITH AVERAGE INCOME
probit response_q avginc_q mob_q iir_q [pw=rakedwgt], vce(cluster id) nocons
margins, dydx(*) post

mat b = e(b)
mat V = vecdiag(e(V))

nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs}))  ///
	  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000) ///
	   , post

mat tmp = r(b)
mat coleq tmp = nlcom
mat b = b, tmp
mat tmp = vecdiag(r(V))
mat coleq tmp = nlcom
mat V = V, tmp
mat V = diag(V)
erepost b=b V=V

eststo probavg

* PROBIT WITH MEDIAN INCOME
probit response_q p90inc_q p50inc_q p10inc_q mob_q [pw=rakedwgt], vce(cluster id) nocons
margins, dydx(*) post

mat b = e(b)
mat V = vecdiag(e(V))

nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
	  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000) ///
	  , post 
	
mat tmp = r(b)
mat coleq tmp = nlcom
mat b = b, tmp
mat tmp = vecdiag(r(V))
mat coleq tmp = nlcom
mat V = V, tmp
mat V = diag(V)
erepost b=b V=V

eststo probmed



# del ;
esttab probavg probmed using "../output/tablea19.tex"
	, replace
	label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
	rename(p50inc_q inc avginc_q inc ) 
	coeflabels(inc "Middle Income" 
			   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
			   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
	cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
	nodepvar mtitles("Average" "Median") collabels(none) onecell
	;
# del cr


****************************************************************************************************************
/* Table A.20: PARTY CONDITION WITH EDUCATION SUPPLEMENT*/
****************************************************************************************************************

u "preferred_sampleRR_uniwts_plus_educ", clear		// here we call in the data that includes the second sample collection, what we refer to as the education supplement
*u "undereducsampRR", clear
** data stuff
cap drop _one
gen _one = 1

gen noveil = veil==0
sum personalinc,d
gen highinc = 1 if personalinc>=`r(p50)'
gen lowinc = 1 if personalinc<=`r(p50)'

* set these here, allows us to change inc from median to mean 
global incmedmrs  59.339 	// median 
global incmrs  71.419	// this is the median of the mean (the other statistics use the median as well)
global mobmrs  68.26
global iirmrs  11.5
global primrs 15
global elimrs 163.384

global pripct 1468.567	// based on linear regression of percentile against bottom 20 income
global elipct 9770.1	// based on linear regression of percentile against top 20 income
global mobpct 2.054		// based on linear regression of percentile against mobility 
global iirpct 1.12088		// based on linear regression of percentile against IIR

gen young = age_1824 ==1 | age_2534==1 | age_3544==1
gen old   = age_4554 ==1 | age_55pl==1
foreach v in p10socB_q p50socB_q p90socB_q avgincsocB_q p10socA_q p50socA_q p90socA_q avgincsocA_q {
	replace `v' = `v'*1000
	}
gen p10incdiff = ln(inc/p10socB_q)
gen p50incdiff = ln(inc/p50socB_q)
gen p90incdiff = ln(inc/p90socB_q)
gen avgincdiff = ln(inc/avgincsocB_q)

label var avginc_q "Middle Income" 
label var p50inc_q "Middle Income" 
label var mob_q "Income Mobility"
label var iir_q "Income Inequality Ratio"
label var p10inc_q "Income 10th Percentile"
label var p90inc_q "Income 90th Percentile"

graph set window fontface "Times New Roman"

preserve
	foreach v in party_dem party_rep party_ind {
		
		if "`v'"=="party_dem" loc name dem
		if "`v'"=="party_ind" loc name ind
		if "`v'"=="party_rep" loc name rep

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_rep==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_ind==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if party_rep==1
			replace grp = 2 if party_ind==1
			}				
		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) , post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 4/6 {
		if "`m'"=="4" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_rep==1
			}
		if "`m'"=="5" {
			cap drop grp
			gen grp = 1 if party_dem==1
			replace grp = 2 if party_ind==1
			}		
		if "`m'"=="6" {
			cap drop grp
			gen grp = 1 if party_rep==1
			replace grp = 2 if party_ind==1
			}	
		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) nocons
		*clogit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) group(id)
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}

	# del ;
	esttab probavgdem probavgind probavgrep probmeddem probmedind probmedrep using "../output/tablea20.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Democrat" "Independent" "Republican" "Democrat" "Independent" "Republican")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	
	esttab test1 test2 test3 test4 test5 test6
		using "../output/tablea20.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
restore


****************************************************************************************************************
/* APPENDIX Table A.21: INCOME CONDITION WITH EDUCATION SUPPLEMENT */
****************************************************************************************************************	


u "preferred_sampleRR_uniwts_plus_educ", clear		// here we call in the data that includes the second sample collection, what we refer to as the education supplement
*u "undereducsampRR", clear
** data stuff
cap drop _one
gen _one = 1

gen noveil = veil==0
sum personalinc,d
gen highinc = 1 if personalinc>=`r(p50)'
gen lowinc = 1 if personalinc<=`r(p50)'

* set these here, allows us to change inc from median to mean 
global incmedmrs  59.339 	// median 
global incmrs  71.419	// this is the median of the mean (the other statistics use the median as well)
global mobmrs  68.26
global iirmrs  11.5
global primrs 15
global elimrs 163.384

global pripct 1468.567	// based on linear regression of percentile against bottom 20 income
global elipct 9770.1	// based on linear regression of percentile against top 20 income
global mobpct 2.054		// based on linear regression of percentile against mobility 
global iirpct 1.12088		// based on linear regression of percentile against IIR

gen young = age_1824 ==1 | age_2534==1 | age_3544==1
gen old   = age_4554 ==1 | age_55pl==1
foreach v in p10socB_q p50socB_q p90socB_q avgincsocB_q p10socA_q p50socA_q p90socA_q avgincsocA_q {
	replace `v' = `v'*1000
	}
gen p10incdiff = ln(inc/p10socB_q)
gen p50incdiff = ln(inc/p50socB_q)
gen p90incdiff = ln(inc/p90socB_q)
gen avgincdiff = ln(inc/avgincsocB_q)

label var avginc_q "Middle Income" 
label var p50inc_q "Middle Income" 
label var mob_q "Income Mobility"
label var iir_q "Income Inequality Ratio"
label var p10inc_q "Income 10th Percentile"
label var p90inc_q "Income 90th Percentile"

graph set window fontface "Times New Roman"

preserve
		*** by income SHOULD WE DO IT WITH 20 and 80?
	cap drop bottominc
	cap drop middleinc
	cap drop topinc
	*keep if veil==1
	_pctile inc  [aw=raked], percentiles(20 80)
	gen bottominc = inc<`r(r1)'
	gen middleinc = inrange(inc,`r(r1)',`r(r2)')
	gen topinc = inc>`r(r2)'
	

	foreach v in bottominc middleinc topinc {
		
		if "`v'"=="bottominc" loc name bot
		if "`v'"=="middleinc" loc name mid
		if "`v'"=="topinc" loc name top

		* PROBIT WITH AVERAGE INCOME
		probit response_q avginc_q mob_q iir_q if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (IIR_mrs: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})) (Mobility_mrs: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})) ///
			  (IIR_wtp: -1*(_b[iir_q]/_b[avginc_q] * ${incmrs}/${iirmrs})*${iirpct}*1000)  (Mobility_wtp: (_b[mob_q]/_b[avginc_q] * ${incmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probavg`name'

		* PROBIT WITH MEDIAN INCOME
		probit response_q p90inc_q p50inc_q p10inc_q mob_q  if `v'==1 [pw=rakedwgt], vce(cluster id) nocons
		margins, dydx(*) post
		mat b = e(b)
		mat V = vecdiag(e(V))

		nlcom (Priority_mrs: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})) (Elite_mrs : (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})) (Mobility_mrs: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})) ///
			  (Priority_wtp: (_b[p10inc_q]/_b[p50inc_q] * ${incmedmrs}/${primrs})*${pripct}) (Elite_wtp: (_b[p90inc_q]/_b[p50inc_q] * ${incmedmrs}/${elimrs})*${elipct}) (Mobility_wtp: (_b[mob_q]/_b[p50inc_q] * ${incmedmrs}/${mobmrs})*${mobpct}*1000), post

		mat tmp = r(b)
		mat coleq tmp = nlcom
		mat b = b, tmp
		mat tmp = vecdiag(r(V))
		mat coleq tmp = nlcom
		mat V = V, tmp
		mat V = diag(V)
		erepost b=b V=V
		eststo probmed`name'
	}

	forval m = 1/3 {
		if "`m'"=="1" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if middleinc==1
			}
		if "`m'"=="2" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if topinc==1
			}		
		if "`m'"=="3" {
			cap drop grp
			gen grp = 1 if topinc==1
			replace grp = 2 if middleinc==1
			}				
		probit response_q i.grp#c.(avginc_q mob_q iir_q) [pw=rakedwgt], vce(cluster id) nocons
		nlcom ///
			(IIR_mrs: (_b[response_q:1b.grp#c.iir_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${iirmrs})-(_b[response_q:2.grp#c.iir_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${iirmrs})) 	///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.avginc_q] * ${incmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.avginc_q] * ${incmrs}/${mobmrs})) , post
		
		mat define b = r(b)
		mat define V = r(V)

		estadd scalar IIR_test= 2*ttail(e(N),abs(b[1,1]/sqrt(V[1,1])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(b[1,2]/sqrt(V[2,2])))
		eststo test`m'
	}
	forval m = 4/6 {
		if "`m'"=="4" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if middleinc==1
			}
		if "`m'"=="5" {
			cap drop grp
			gen grp = 1 if bottominc==1
			replace grp = 2 if topinc==1
			}		
		if "`m'"=="6" {
			cap drop grp
			gen grp = 1 if topinc==1
			replace grp = 2 if middleinc==1
			}	
		probit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) nocons
		*clogit response_q i.grp#c.(p90inc_q p50inc_q p10inc_q mob_q  ) [pw=rakedwgt], vce(cluster id) group(id)
		nlcom ///
			(Elite_mrs: (_b[response_q:1b.grp#c.p90inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})-(_b[response_q:2.grp#c.p90inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${elimrs})) 		///
			(Priority_mrs: (_b[response_q:1b.grp#c.p10inc_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${primrs})-(_b[response_q:2.grp#c.p10inc_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${primrs})) ///
			(Mobility_mrs: (_b[response_q:1b.grp#c.mob_q]/_b[response_q:1b.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})-(_b[response_q:2.grp#c.mob_q]/_b[response_q:2.grp#c.p50inc_q] * ${incmedmrs}/${mobmrs})) 	, post
		mat define beta = r(b)
		mat define VarCov = r(V)

		estadd scalar ELI_test= 2*ttail(e(N),abs(beta[1,1]/sqrt(VarCov[1,1])))
		estadd scalar PRI_test= 2*ttail(e(N),abs(beta[1,2]/sqrt(VarCov[2,2])))
		estadd scalar MOB_test= 2*ttail(e(N),abs(beta[1,3]/sqrt(VarCov[3,3])))
		eststo test`m'
	}

	# del ;
	esttab probavgbot probavgmid probavgtop probmedbot probmedmid probmedtop using "../output/tablea21.tex"
		, replace
		label order(inc mob_q iir_q p10inc_q p90inc_q IIR_mrs Mobility_mrs Priority_mrs Elite_mrs IIR_wtp Mobility_wtp Priority_wtp Elite_wtp)   
		rename(p50inc_q inc avginc_q inc ) 
		coeflabels(inc "Middle Income" 
				   IIR_mrs "Income Inequality Ratio" Mobility_mrs "Income Mobility" Priority_mrs "Income 10th Percentile" Elite_mrs "Income 90th Percentile" 
				   IIR_wtp "Income Inequality Ratio" Mobility_wtp "Income Mobility" Priority_wtp "Income 10th Percentile" Elite_wtp "Income 90th Percentile" )
		cells(b(star fmt(3)) se(par(( )) fmt(3)))  style(tex) star(* 0.10 ** 0.05 *** 0.01) 
		nodepvar mgroups("Average" "Median", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
		mtitles("Bottom 20 Income" "Middle 60 Income" "Top 20 Income" "Bottom 20 Income" "Middle 60 Income" "Top 20 Income")  alignment(D{.}{.}{-1}) page(dcolumn) nonumber onecell
		;
	
	esttab test1 test2 test3 test4 test5 test6
		using "../output/tablea21.tex"
		, append
		scalars("IIR_test Income Inequality" "MOB_test Income Mobility" "PRI_test Income 10th Percentile" "ELI_test Income 90th Percentile") 
		mtitles("Average" "Median")
		rename(IIR_test "Income Inequality Ratio" MOB_test "Income Mobility" PRI_test "Income 10th Percentile" ELI_test "Income 90th Percentile")
		drop(*)  noobs style(tex) star(* 0.10 ** 0.05 *** .01)  nodepvar collabels(none) onecell
	;

	# del cr
restore	

****************************************************************************************************************
/* APPENDIX Table A.22 , A.22: ADAPTIVE MRS: MOBILITY & INEQUALITY, ALL AND THEN BY PARTY , PREDICTORS OF THE MRS */
****************************************************************************************************************	

u "preferred_sampleRR_uniwts_plus_educ", clear		// here we call in the data that includes the second sample collection, what we refer to as the education supplement
*u "undereducsampRR", clear
** data stuff
cap drop _one
gen _one = 1

gen noveil = veil==0
sum personalinc,d
gen highinc = 1 if personalinc>=`r(p50)'
gen lowinc = 1 if personalinc<=`r(p50)'

* set these here, allows us to change inc from median to mean 
global incmedmrs  59.339 	// median 
global incmrs  71.419	// this is the median of the mean (the other statistics use the median as well)
global mobmrs  68.26
global iirmrs  11.5
global primrs 15
global elimrs 163.384

global pripct 1468.567	// based on linear regression of percentile against bottom 20 income
global elipct 9770.1	// based on linear regression of percentile against top 20 income
global mobpct 2.054		// based on linear regression of percentile against mobility 
global iirpct 1.12088		// based on linear regression of percentile against IIR

gen young = age_1824 ==1 | age_2534==1 | age_3544==1
gen old   = age_4554 ==1 | age_55pl==1
foreach v in p10socB_q p50socB_q p90socB_q avgincsocB_q p10socA_q p50socA_q p90socA_q avgincsocA_q {
	replace `v' = `v'*1000
	}
gen p10incdiff = ln(inc/p10socB_q)
gen p50incdiff = ln(inc/p50socB_q)
gen p90incdiff = ln(inc/p90socB_q)
gen avgincdiff = ln(inc/avgincsocB_q)

label var avginc_q "Middle Income" 
label var p50inc_q "Middle Income" 
label var mob_q "Income Mobility"
label var iir_q "Income Inequality Ratio"
label var p10inc_q "Income 10th Percentile"
label var p90inc_q "Income 90th Percentile"

graph set window fontface "Times New Roman"

preserve
	gen ln_income = ln(inc)
	/*gen top_income=(inc==175000)
	replace ln_income=0 if inc==175000
	label variable top_income "Household income $\geq$ 175k"
	*/
	gen age=age_alt
	replace age=21 if age_alt==. & age_1824==1
	replace age=30 if age_alt==. & age_2534==1
	replace age=40 if age_alt==. & age_3544==1
	replace age=50 if age_alt==. & age_4554==1
	replace age=64 if age_alt==. & age_55pl==1
	label variable age "Age"

	gen All=1
	gen educ_hsless = educ_hs | educ_none
	gen educ_collplus = educ_4yr | educ_4yrplus
	gen educ_some = educ_2yr | educ_somecoll

	label variable educ_some "Some college"
	label variable educ_collplus "Bachelor or above"
	label variable party_dem "Democrat"
	label variable party_ind "Independent"
	label variable ln_income "Ln household income"
	label variable age_alt "Age"
	label variable gender_male "Male"
	label variable race_black "Black"
	label variable race_hispanic "Hispanic"
	label variable race_other "Other race"
	replace past=(past>0 & past!=.)
	label variable past "Has greater income than parents"
	replace belief_mob=(belief_mob>=3 & belief_mob!=.)
	label variable belief_mob "Believes upper mobility is common"
	label variable future "Believes children have a better future"

	keep if question==1
	tab mobMRS, gen(d_)

	// COLOQUE LÍMITE INFERIOR 0
	gen mobMRS1 = 0 if d_1==1
	gen mobMRS2 = 307.87820 if d_1==1
	replace mobMRS1 = 307.87820 if d_2==1
	replace mobMRS2 = 641.12316 if d_2==1
	replace mobMRS1 = 641.12316 if d_3==1
	replace mobMRS2 = 1034.21239 if d_3==1
	replace mobMRS1 = 1034.21239 if d_4==1
	replace mobMRS2 = 1547.80822 if d_4==1
	replace mobMRS1 = 1547.80822 if d_5==1
	replace mobMRS2 = 2316.45870 if d_5==1
	replace mobMRS1 = 2316.45870 if d_6==1
	replace mobMRS2 = 3736.73959 if d_6==1
	replace mobMRS1 = 3736.73959 if d_7==1
	replace mobMRS2 = 7781.35739 if d_7==1
	replace mobMRS1 = 7781.35739 if d_8==1
	replace mobMRS2 = . if d_8==1

	drop d_*

	tab incineqMRS, gen(d_)

	// COLOQUE LÍMITE INFERIOR 0
	gen incineqMRS1 = 0 if d_1==1
	gen incineqMRS2 = 369.656388 if d_1==1
	replace incineqMRS1 = 369.656388 if d_2==1
	replace incineqMRS2 = 769.7695792 if d_2==1
	replace incineqMRS1 = 769.7695792 if d_3==1
	replace incineqMRS2 = 1241.735268 if d_3==1
	replace incineqMRS1 = 1241.735268 if d_4==1
	replace incineqMRS2 = 1858.388158 if d_4==1
	replace incineqMRS1 = 1858.388158 if d_5==1
	replace incineqMRS2 = 2781.274426 if d_5==1
	replace incineqMRS1 = 2781.274426 if d_6==1
	replace incineqMRS2 = 4486.545895 if d_6==1
	replace incineqMRS1 = 4486.545895 if d_7==1
	replace incineqMRS2 = 9342.748178 if d_7==1
	replace incineqMRS1 = 9342.748178 if d_8==1
	replace incineqMRS2 = . if d_8==1

	drop d_*

	sum personalinc, d
	gen higher_income=(personalinc>r(p50)) if personalinc!=.
	gen lower_income=(personalinc<=r(p50)) if personalinc!=1
	label variable higher_income "Income higher than median"
	label variable lower_income "Income lower than median"

	_pctile inc [aw=raked], percentiles(20 80)
	gen bottominc = inc<`r(r1)'
	gen middleinc = inrange(inc,`r(r1)',`r(r2)')
	gen topinc = inc>`r(r2)' 
	lab var middleinc "Middle 60 Income"
	lab var topinc "Top 20 Income"

	foreach dv in mobMRS incineqMRS {
		//intreg `dv'1 `dv'2 educ_some educ_collplus party_dem party_ind higher_income age_2534 age_3544 age_4554 age_55pl gender_male race_black race_hispanic race_other past future belief_mob  [pw=rakedwgt] , r
		intreg `dv'1 `dv'2 educ_some educ_collplus party_dem party_ind middleinc topinc /*ln_income*/ age gender_male race_black race_hispanic race_other past belief_mob  [pw=rakedwgt] , r

		est sto int`dv'
		
		foreach g in party_dem party_ind party_rep {
			display ("`dv' + `g'")
			intreg `dv'1 `dv'2 educ_some educ_collplus middleinc topinc /*ln_income*/ age gender_male race_black race_hispanic race_other past belief_mob if `g'==1  [pw=rakedwgt], r
		est sto int`dv'`g'
	}
	}

	esttab  intmobMRS intmobMRSparty_dem intmobMRSparty_ind intmobMRSparty_rep using "../output/tablea22.tex", style(tex) replace ///
		cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
		label star(* 0.10 ** 0.05 *** .01) ///
		mtitles("All" "Dem" "Indep" "Rep")
		
	esttab intincineqMRS intincineqMRSparty_dem intincineqMRSparty_ind intincineqMRSparty_rep using "../output/tablea23.tex", style(tex) replace ///
		cells(b(star fmt(3)) se(par(( )) fmt(3))) ///
		label star(* 0.10 ** 0.05 *** .01) ///
		mtitles("All" "Dem" "Indep" "Rep")	
		
	ta mobMRS , gen(m_)
	gen mobmin = m_1==1
	gen mobmax = m_8==1
	ta incineqMRS, gen(i_)
	gen iirmin = i_1==1
	gen iirmax = i_8==1

	gen extreme1 = . 
	replace extreme1 = 2 if mobmin==1 
	replace extreme1 = 3 if mobmax==1 
	replace extreme1 = 4 if iirmin==1 
	replace extreme1 = 5 if iirmax==1
	replace extreme1 = 6 if mobmin==1 & iirmin==1 
	replace extreme1 = 7 if mobmax==1 & iirmax==1
	replace extreme1 = 8 if iirmax==1 & mobmin==1
	replace extreme1 = 9 if iirmin==1 & mobmax==1
	replace extreme1 = 1 if extreme1==.
	label define extreme1 1 "Normies" 2 "Mobility Min" 3 "Mobility Max" 4 "IIR Min" 5 "IIR Max" 6 "Mob+IIR Min" 7 "Mob+IIR Max" 8 "IIR Max+Mob Min" 9 "IIR Min+Mob Max", replace
	label values extreme1 extreme1

	gen extreme2 = inlist(extreme1,1,8,9)
	replace extreme2 = 2 if inlist(extreme1,2,4,6)
	replace extreme2 = 3 if inlist(extreme1,3,5,7)
	label define extreme2 1 "Normies" 2 "Min MRS" 3 "Max MRS" 
	label values extreme2 extreme2
	
	ta extreme2, gen(extreme_)
	foreach dv in mobMRS incineqMRS {
	intreg `dv'1 `dv'2 educ_some educ_collplus party_dem party_ind middleinc topinc /*ln_income*/ age gender_male race_black race_hispanic race_other past belief_mob  [pw=rakedwgt] , r
	}
	
	keep id group extreme1 extreme2 mobmin mobmax iirmin iirmax
	tempfile hold
	save `hold'
restore


****************************************************************************************************************
/* APPENDIX FIGURE A.6: DECISION TREE INCOME MOBILITY */
****************************************************************************************************************	

****************************************************************************************************************
/* APPENDIX FIGURE A.7: DECISION TREE INCOME EQUALITY */
****************************************************************************************************************	

****************************************************************************************************************
/* APPENDIX FIGURE A.8: NON-PARAMETRIC RESULTS */
****************************************************************************************************************		
u "preferred_sampleRR_uniwts", clear
*u "undereducsampRR", clear
** data stuff
cap drop _one
gen _one = 1

gen noveil = veil==0
sum personalinc,d
gen highinc = 1 if personalinc>=`r(p50)'
gen lowinc = 1 if personalinc<=`r(p50)'

* set these here, allows us to change inc from median to mean 
global incmedmrs  59.339 	// median 
global incmrs  71.419	// this is the median of the mean (the other statistics use the median as well)
global mobmrs  68.26
global iirmrs  11.5
global primrs 15
global elimrs 163.384

global pripct 1468.567	// based on linear regression of percentile against bottom 20 income
global elipct 9770.1	// based on linear regression of percentile against top 20 income
global mobpct 2.054		// based on linear regression of percentile against mobility 
global iirpct 1.12088		// based on linear regression of percentile against IIR

gen young = age_1824 ==1 | age_2534==1 | age_3544==1
gen old   = age_4554 ==1 | age_55pl==1
foreach v in p10socB_q p50socB_q p90socB_q avgincsocB_q p10socA_q p50socA_q p90socA_q avgincsocA_q {
	replace `v' = `v'*1000
	}
gen p10incdiff = ln(inc/p10socB_q)
gen p50incdiff = ln(inc/p50socB_q)
gen p90incdiff = ln(inc/p90socB_q)
gen avgincdiff = ln(inc/avgincsocB_q)

label var avginc_q "Middle Income" 
label var p50inc_q "Middle Income" 
label var mob_q "Income Mobility"
label var iir_q "Income Inequality Ratio"
label var p10inc_q "Income 10th Percentile"
label var p90inc_q "Income 90th Percentile"

graph set window fontface "Times New Roman"

preserve

	set matsize 800 //10000, permanently
	set scheme burd

	rename response_q prefs	
	rename raked peso
	rename p10socB_q p10B
	rename p10socA_q p10A
	rename p90socB_q p90B
	rename p90socA_q p90A
	rename p50socB_q p50B
	rename p50socA_q p50A
	rename mobsocB_q mobB
	rename mobsocA_q mobA
	gen iirA = p90A/p10A
	gen iirB = p90B/p10B
	keep id question prefs p10? p50? p90? mob? iir? peso

	foreach v in p10 p50 p90 mob iir {
	foreach m in A B {
		egen temp = group(`v'`m')
		drop `v'`m'
		rename temp `v'`m'
		}
		}
	reshape long p10 p50 p90 mob iir, i(id question prefs peso) j(society) string
	gen choice = (prefs==0 & society=="A") | (prefs==1 & society=="B")

	ta p10, gen(p10_)
	ta p50, gen(p50_)
	ta p90, gen(p90_)
	ta mob, gen(mob_)
	ta iir, gen(iir_)

	forval y = 1/9 {
	forval x = 1/9 {
		gen p10`x'p50`y' = p10_`x'*p50_`y'
		gen p90`x'p50`y' = p90_`x'*p50_`y'
		gen mob`x'p50`y' = mob_`x'*p50_`y'
		}
	forval x = 1/80 {
		gen iir`x'p50`y' = iir_`x'*p50_`y'
		}
		}
	tempname memhold
	tempfile results
	postfile `memhold' model str45 description xvar yvar beta se using `results'

	*** priority
	reg choice p10*p50* p90_* mob_* [aw=peso] , cluster(id) nocons

	forval x = 1/9{
	forval y = 1/9{
		loc ed = `x'
		loc inc = `y'
		post `memhold' (1) ("P10 Income by P50 Income") (`ed')  (`inc') (_b[p10`x'p50`y'])  (_se[p10`x'p50`y'])
		}
		}
	** elite
	reg choice p90*p50* p10_* mob_* [aw=peso] , cluster(id) nocons

	forval x = 1/9{
	forval y = 1/9{
		loc ed = `x'
		loc inc = `y'
		post `memhold' (2) ("P90 Income by P50 Income") (`ed')  (`inc') (_b[p90`x'p50`y'])  (_se[p90`x'p50`y'])
		}
		}
		
	** mobility
	reg choice mob*p50* iir_*  [aw=peso] , cluster(id) nocons

	forval x = 1/9{
	forval y = 1/9{
		loc ed = `x'
		loc inc = `y'
		post `memhold' (3) ("Mobility by P50 Income") (`ed')  (`inc') (_b[mob`x'p50`y'])  (_se[mob`x'p50`y'])
		}
		}
		
	** inc ineq
	reg choice iir*p50* mob_*  [aw=peso] , cluster(id) nocons

	forval x = 1/80{
	forval y = 1/9{
		loc ed = 81-`x'
		loc inc = `y'
		post `memhold' (4) ("IIR by P50 Income") (`ed')  (`inc') (_b[iir`x'p50`y'])  (_se[iir`x'p50`y'])
		}
		}	
		
	postclose `memhold'
	u `results', clear

	# del ;
	graph tw contour beta  yvar xvar if model==1 , 
		levels(9)  zlabel(#9, format(%9.2f)) interp(thinplatespline) 
		ytitle("Middle Incomes", size(medium))
		xtitle("Bottom Incomes ", size(medium))
		ztitle("") xlab(1(1)9) ylab(1(1)9)
		/*title("Social Preferences Income/Mobility Trade-Off", size(medium))*/
		xlab(1 "$9k" 3 "$13k" 5 "$15k" 7 "$17k" 9 "$23k", labsize(medium))
		ylab(1 "$41k" 2 "$48k" 3 "$52k" 4 "$56k" 5 "$59k" 6 "$62k" 7 "$66k" 8 "$70k" 9 "$75k", labsize(medium) angle(hori))
		name(p10, replace) graphregion(m(r+1)) plotregion(m(zero))  aspectratio(1) ysize(2.8) xsize(3.5) heatmap scheme(s1color) crule(intensity)
		ecolor(green); //scolor(white) ecolor(black);
	# del cr
	graph export "../output/figa8a.pdf", replace as(pdf)


	# del ;
	graph tw contour beta  yvar xvar if model==2 , 
		levels(9)  zlabel(#9, format(%9.2f)) interp(thinplatespline) 
		ytitle("Middle Incomes", size(medium))
		xtitle("Top Incomes ", size(medium))
		ztitle("") xlab(1(1)9) ylab(1(1)9)
		/*title("Social Preferences Income/Mobility Trade-Off", size(medium))*/
		xlab(1 "$126k" 3 "$148k" 5 "$163k" 7 "$182k" 9 "$208k", labsize(medium))
		ylab(1 "$41k" 2 "$48k" 3 "$52k" 4 "$56k" 5 "$59k" 6 "$62k" 7 "$66k" 8 "$70k" 9 "$75k", labsize(medium)angle(hori))
		name(p90, replace) graphregion(m(r+1)) plotregion(m(zero))  aspectratio(1) ysize(2.8) xsize(3.5) heatmap scheme(s1color) crule(intensity) 
		ecolor(red); //scolor(white) ecolor(black);
	# del cr
	graph export "../output/figa8b.pdf", replace as(pdf)
	
	# del ;
	graph tw contour beta  yvar xvar if model==3 , 
		levels(9)  zlabel(#9, format(%9.2f)) interp(thinplatespline) 
		ytitle("Middle Incomes", size(medium))
		xtitle("Mobility", size(medium))
		ztitle("") xlab(1(1)9) ylab(1(1)9)
		/*title("Social Preferences Income/Mobility Trade-Off", size(medium))*/
		xlab(1 "62%" 3 "65%" 5 "68%" 7 "72%" 9 "80%", labsize(medium))
		ylab(1 "$41k" 2 "$48k" 3 "$52k" 4 "$56k" 5 "$59k" 6 "$62k" 7 "$66k" 8 "$70k" 9 "$75k", labsize(medium)angle(hori))
		name(mob, replace) graphregion(m(r+1)) plotregion(m(zero))  aspectratio(1) ysize(2.8) xsize(3.5) heatmap scheme(s1color) crule(intensity) 
		ecolor(cranberry); //scolor(white) ecolor(black);
	# del cr
	graph export "../output/figa8c.pdf", replace as(pdf)
	
	# del ;
	graph tw contour beta  yvar xvar if model==4 , 
		levels(9)  zlabel(#9, format(%9.2f)) interp(shepard) 
		ytitle("Middle Incomes", size(medium))
		xtitle("Income Inequality Ratio", size(medium))
		ztitle("") xlab(1(1)80) ylab(1(1)9) 
		/*title("Social Preferences Income/Mobility Trade-Off", size(medium))*/
		xlab(1 "22.1" 21 "13.6" 41 "11.0" 61 "9.1" 81 "5.5", labsize(medium))
		ylab(1 "$41k" 2 "$48k" 3 "$52k" 4 "$56k" 5 "$59k" 6 "$62k" 7 "$66k" 8 "$70k" 9 "$75k", labsize(medium)angle(hori))
		name(iir, replace) graphregion(m(r+1)) plotregion(m(zero))  aspectratio(1) ysize(2.8) xsize(3.5) heatmap scheme(s1color) crule(intensity)
		ecolor(blue) ; //scolor(white) ecolor(black);
	# del cr
	graph export "../output/figa8d.pdf", replace as(pdf)

restore


****************************************************************************************************************
/* Figure A9: ISO-UTILITY BY PARTY */
****************************************************************************************************************		

gen graph_p10=9.6+(_n-1)*(22.801-9.6)/100 if _n<=101

gen graph_p90=125.651+(_n-1)*(208.496-125.651)/100 if _n<=101

gen graph_mob=61.51+(_n-1)*(79.7-61.51)/100 if _n<=101

gen graph_ineq=15.12-(_n-1)*(15.12-8.42)/100 if _n<=101

foreach i of numlist 71 79 92{
	local U`i'=ln(`i')*`a'+ln(15.12)*`b'
	gen curve_ineq_`i'=exp((`U`i''-`b'*ln(graph_ineq))/`a')
}

twoway (line curve_ineq_71 graph_ineq, sort) (line curve_ineq_79 graph_ineq, sort)  (line curve_ineq_92 graph_ineq, sort), ///
	legend(off) xsize(3.5) ysize(3.5)  ytitle("Average income thousands", size(medlarge)) xtitle("Income Inequality Ratio (90/10)", size(medlarge)) ylabel(50(10)90, angle(hori)) scheme(s1mono)  name(d, replace) xscale(reverse) aspectratio(1) //title(Income Inequality - Avg. Income)

graph export "../output/fig2d.pdf", replace as(pdf)

// Isoutilities p10 ideology 
foreach var in dem ind rep { 

	// Isocurve p10
	//probit prob inc mobil incineq [pw=peso], vce(cluster id) nocons
	probit response_q p90inc_q p50inc_q p10inc_q mob_q  [pw=rakedwgt] if party_`var'==1, vce(cluster id) nocons
	matrix define beta_p50_p10=e(b)'

	local a=beta_p50_p10[2,1]
	local b=beta_p50_p10[3,1]

	foreach i of numlist 66  {
		local U`i'=ln(`i')*`a'+ln(9.6)*`b'
		gen curve_p10_`i'`var'=exp((`U`i''-`b'*ln(graph_p10))/`a')
		replace curve_p10_`i'`var'=. if curve_p10_`i'`var'<40
		}
	}
twoway (line curve_p10_66dem graph_p10, sort)  (line curve_p10_66ind graph_p10, lp(dash) sort)  (line curve_p10_66rep graph_p10, lp(longdash) sort), ///
	legend(order(1 "Democrat" 2 "Independent" 3 "Republican") symxsize(*.5) size(small) rows(1)) xsize(3.5) ysize(3.5)  ytitle("Middle 60% income thousands", size(medlarge)) xtitle("Bottom 20% Average Income", size(medlarge)) ylabel(40(10)80, angle(hori)) scheme(s1mono) name(a_party, replace)  
graph export "../output/figa9a.pdf", replace as(pdf)
	
foreach var in dem ind rep { 
	// Isocurve p90
	*probit prob inc mobil incineq [pw=peso], vce(cluster id) nocons
	probit response_q p90inc_q p50inc_q p10inc_q mob_q  [pw=rakedwgt] if party_`var'==1, vce(cluster id) nocons
	matrix define beta_p50_p90=e(b)'

	local a=beta_p50_p90[2,1]
	local b=beta_p50_p90[1,1]

	foreach i of numlist 66 {
		local U`i'=ln(`i')*`a'+ln(125.651)*`b'
		gen curve_p90_`i'`var'=exp((`U`i''-`b'*ln(graph_p90))/`a')
		replace curve_p90_`i'`var'=. if curve_p90_`i'`var'<40
		}
	}
twoway (line curve_p90_66dem graph_p90, sort) (line curve_p90_66ind graph_p90, lp(dash) sort) (line curve_p90_66rep graph_p90, lp(longdash) sort), ///
	legend(order(1 "Democrat" 2 "Independent" 3 "Republican") symxsize(*.5) size(small) rows(1)) xsize(3.5) ysize(3.5)  ytitle("Middle 60% income thousands", size(medlarge)) xtitle("Top 20% Average Income", size(medlarge)) ylabel(40(10)80, angle(hori)) scheme(s1mono) name(b_party, replace)  
graph export "../output/figa9b.pdf", replace as(pdf)


	// Isocurve mobility
foreach var in dem ind rep { 
	probit response_q avginc_q mob_q iir_q [pw=rakedwgt] if party_`var'==1, vce(cluster id) nocons
	matrix define beta_p50_mob=e(b)'

	// I use quadratic equation solution to get the isocurve
	local a=beta_p50_mob[1,1]
	local b=beta_p50_mob[2,1]

	foreach i of numlist 79 {
		local U`i'=ln(`i')*`a'+ln(61.51)*`b'
		gen curve_mob_`i'`var'=exp((`U`i''-`b'*ln(graph_mob))/`a')
		}
	}
twoway (line curve_mob_79dem graph_mob, sort) (line curve_mob_79ind graph_mob, lp(dash) sort)  (line curve_mob_79rep graph_mob, lp(longdash) sort), ///
	legend(order(1 "Democrat" 2 "Independent" 3 "Republican") symxsize(*.5) size(small) rows(1)) xsize(3.5) ysize(3.5)  ytitle("Average income thousands", size(medlarge)) xtitle("Income mobility", size(medlarge)) ylabel(50(10)90, angle(hori)) scheme(s1mono)  name(c_party, replace)  //title(Income Mobility - Avg. Income)
graph export "../output/figa9c.pdf", replace as(pdf)

	
	// Isocurve income equality
foreach var in dem ind rep { 
	probit response_q avginc_q mob_q iir_q [pw=rakedwgt] if party_`var'==1, vce(cluster id) nocons
	matrix define beta_p50_ineq=e(b)'


	// I use quadratic equation solution to get the isocurve
	local a=beta_p50_ineq[1,1]
	local b=beta_p50_ineq[3,1]

	foreach i of numlist 79{
		local U`i'=ln(`i')*`a'+ln(15.12)*`b'
		gen curve_ineq_`i'`var'=exp((`U`i''-`b'*ln(graph_ineq))/`a')
		}
	}
twoway (line curve_ineq_79dem graph_ineq, sort) (line curve_ineq_79ind graph_ineq, lp(dash) sort)  (line curve_ineq_79rep graph_ineq, lp(longdash) sort), ///
	legend(order(1 "Democrat" 2 "Independent" 3 "Republican") symxsize(*.5) size(small) rows(1)) xsize(3.5) ysize(3.5)  ytitle("Average income thousands", size(medlarge)) xtitle("Income Inequality Ratio (90/10)", size(medlarge)) ylabel(50(10)90, angle(hori)) scheme(s1mono)  name(d_party, replace) xscale(reverse) //title(Income Inequality - Avg. Income)
graph export "../output/figa9d.pdf", replace as(pdf)

